package com.campos.common;

import android.os.Environment;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Config {

    private static Config g_config=null;
    public static Config instance(){
        if(g_config == null){
            g_config = new   Config();
        }
        return g_config;
    }

    public String getOrCreateProjectPath(){
        if(_currentPrjName.equals("0")){
            newPorject();
        }
        return  getCurrentProjectPath();
    }

    public String getCurrentProjectPath(){
        File rootpath = Environment.getExternalStorageDirectory();
        return rootpath.getAbsolutePath() + "/campos/" + _currentPrjName + "/";
    }
    public String getAppDataPath(){
        File rootpath = Environment.getExternalStorageDirectory();
        return rootpath.getAbsolutePath() + "/campos/";
    }
    public String getCurrentProjPath_IMG(){
        return getCurrentProjectPath() + "images/";
    }
    public String getCurrentImageFilePath(){
        String files = getCurrentProjPath_IMG() +String.format("%04d", _imageIndex)+ ".jpg";
        return files;
    }
    public String getCurrentImageFilePath(int index){
        String files = getCurrentProjPath_IMG() +String.format("%04d", index)+ ".jpg";
        return files;
    }
    public void makeNextImage(){
        _imageIndex += 1;
    }
    public int getCurrentImageIndex(){
        return _imageIndex;
    }
    public String getCurrentProjPath_ImageTimeStamp(){
        return getCurrentProjectPath() + "image_timestamp.txt";
    }
    public String getCurrentProjPath_GPSInfo(){
        return getCurrentProjectPath() + "gps_info.txt";
    }
    public String getCurrentProjPath_IMUInfo(){
        return getCurrentProjectPath() + "imu_info.txt";
    }
    public String getCurrentProjPath_IMUCalibInfo(){
        return getCurrentProjectPath() + "imu_calib_info.txt";
    }
    public void newPorject(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date dt = new Date();
        String gpstimestr = simpleDateFormat.format(dt);
        this._currentPrjName = gpstimestr;

    }
    private String _currentPrjName="0";
    private int _imageIndex = 1;
}
